import type { TFunction, i18n } from 'i18next';
import { METRO_STATUS } from '@/utils/constants';
import { getMetroCityList } from '@/servers/metro/city';
import { getMetroTypeList } from '@/servers/metro/type';
import LineColor from '@/pages/metro/line/components/LineColor';

// 搜索数据
export const searchList = (t: TFunction, i18n: i18n): BaseSearchList[] => [
  {
    label: t('metro.cityName'),
    name: 'cityCode',
    component: 'ApiSelect',
    componentProps: {
      api: getMetroCityList,
      fieldNames: { label: i18n.language === 'zh' ? 'cityName' : 'citySpell', value: 'cityCode' },
    },
  },
  {
    label: t('metro.lineName'),
    name: 'lineName',
    component: 'Input',
  },
  {
    label: t('metro.lineStatus'),
    name: 'lineStatus',
    component: 'Select',
    componentProps: {
      options: METRO_STATUS(t),
    },
  },
  {
    label: t('metro.lineType'),
    name: 'lineType',
    component: 'ApiSelect',
    componentProps: {
      api: getMetroTypeList,
      fieldNames: { label: 'typeName', value: 'id' },
    },
  },
];

/**
 * 表格数据
 * @param t
 * @param optionRender - 渲染操作函数
 * @param i18n
 */
export const tableColumns = (
  t: TFunction,
  optionRender: TableOptions<object>,
  i18n: i18n,
): TableColumn[] => {
  return [
    {
      title: t('metro.lineSort'),
      dataIndex: 'lineSort',
    },
    {
      title: t('metro.cityName'),
      dataIndex: i18n.language === 'zh' ? 'cityName' : 'citySpell',
    },
    {
      title: t('metro.lineName'),
      dataIndex: 'lineName',
      render: (text, record) => <LineColor text={text} record={record} />,
    },
    {
      title: t('metro.lineType'),
      dataIndex: 'typeName',
    },
    {
      title: t('metro.lineStatus'),
      dataIndex: 'lineStatus',
      enum: METRO_STATUS(t),
      ellipsis: false,
    },
    {
      title: t('metro.enableDate'),
      dataIndex: 'enableDate',
    },
    {
      title: t('metro.lineCompany'),
      dataIndex: 'lineCompany',
    },
    {
      title: t('public.operate'),
      dataIndex: 'operate',
      width: 240,
      fixed: 'right',
      render: (value: unknown, record: object) => optionRender(value, record),
    },
  ];
};

// 新增数据
export const createList = (t: TFunction, i18n: i18n, lineStatus: string): BaseFormList[] => [
  {
    label: t('metro.cityCode'),
    name: 'cityCode',
    rules: FORM_REQUIRED,
    component: 'ApiSelect',
    componentProps: {
      api: getMetroCityList,
      fieldNames: { label: i18n.language === 'zh' ? 'cityName' : 'citySpell', value: 'cityCode' },
    },
  },
  {
    label: t('metro.lineCode'),
    name: 'lineCode',
    component: 'Input',
    rules: FORM_REQUIRED,
  },
  {
    label: t('metro.lineName'),
    name: 'lineName',
    rules: FORM_REQUIRED,
    component: 'Input',
  },
  {
    label: t('metro.lineEn'),
    name: 'lineEn',
    component: 'Input',
    rules: FORM_REQUIRED,
  },
  {
    label: t('metro.lineCycle'),
    name: 'lineCycle',
    component: 'Switch',
  },
  {
    label: t('metro.lineColor'),
    name: 'lineColor',
    component: 'ColorPicker',
    rules: FORM_REQUIRED,
  },
  {
    label: t('metro.lineType'),
    name: 'lineType',
    rules: FORM_REQUIRED,
    component: 'ApiSelect',
    componentProps: {
      api: getMetroTypeList,
      fieldNames: { label: 'typeName', value: 'id' },
    },
  },
  {
    label: t('metro.lineStatus'),
    name: 'lineStatus',
    rules: FORM_REQUIRED,
    component: 'RadioGroup',
    componentProps: {
      options: METRO_STATUS(t),
    },
  },
  {
    label: t('metro.enableDate'),
    name: 'enableDate',
    component: 'DatePicker',
    rules: FORM_REQUIRED,
    hidden: lineStatus !== 'SERVING',
  },
  {
    label: t('metro.lineCompany'),
    name: 'lineCompany',
    component: 'Input',
  },
  {
    label: t('metro.lineLogo'),
    name: 'lineLogo',
    component: 'Input',
  },
  {
    label: t('metro.lineSort'),
    name: 'lineSort',
    rules: FORM_REQUIRED,
    component: 'InputNumber',
  },
];
